<?php
class modules extends main{

    //Self used Modules
    protected static $modules;
    
    // Gestion des modules
    public static function getModules(){
        $sql = "SELECT * FROM ".parent::getConfig('db_prefix')."modules";
        $tab = dao::request_assoc($sql);
        
        return $tab;
    }
    
    public static function searchModule($word){
        $sql = "SELECT * FROM ".parent::getConfig('db_prefix')."modules AS m WHERE m.name = '".$word."' OR m.urlname = '".$word."'";
        $tab = dao::request_assoc($sql);
        if($tab != false)
                $tab = $tab[0];
        return $tab;
    }
    
    //Appel de module
    public static function getDefaultModule($admin = false){
        if($admin){
            $sql = "SELECT * FROM ".parent::getConfig('db_prefix')."modules AS m WHERE m.back = 1 AND m.default = 1";
            $tab = dao::request_assoc($sql);
            if($tab != false)
                    $tab = $tab[0];
            return $tab;
        }else{
            $sql = "SELECT * FROM ".parent::getConfig('db_prefix')."modules AS m WHERE m.front = 1 AND m.default = 1";
            $tab = dao::request_assoc($sql);
            if($tab != false)
                    $tab = $tab[0];
            return $tab;
        }
    }
    
    //Add module infos into $modules
    public static function addModuleInfos($data){
        self::$modules[$data['urlname']] = $data;
        return self::$modules[$data['urlname']];
    }
    
    //Get all infos module from urlname
    public static function getModuleInfos($modurlname){
        return self::$modules[$modurlname];
    }
    
    //Get specific info module from urlname
    public static function getModuleInfo($modurlname,$info){
        return self::$modules[$modurlname][$info];
    }
    
    //Get module listing
    public static function getModulesListing($onlyBO = false){
        $sql = "SELECT * FROM ".parent::getConfig('db_prefix')."modules AS m WHERE ";
        ($onlyBO) ? $sql .= "back = 1" : $sql .= "1";
        $result = dao::request_assoc($sql);
        if($result){
            return $result;
        }else{
            return false;
        }
    }
}
?>